package com.ruoyi.funding.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.funding.domain.FundingSource;
import com.ruoyi.funding.service.IFundingSourceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 资金来源Controller
 * 
 * @author ycl
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/source")
public class FundingSourceController extends BaseController
{
    @Autowired
    private IFundingSourceService fundingSourceService;

    /**
     * 查询资金来源列表
     */
    @RequiresPermissions("funding:source:list")
    @GetMapping("/list")
    public TableDataInfo list(FundingSource fundingSource)
    {
        startPage();
        List<FundingSource> list = fundingSourceService.selectFundingSourceList(fundingSource);
        return getDataTable(list);
    }

    /**
     * 导出资金来源列表
     */
    @RequiresPermissions("funding:source:export")
    @Log(title = "资金来源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FundingSource fundingSource)
    {
        List<FundingSource> list = fundingSourceService.selectFundingSourceList(fundingSource);
        ExcelUtil<FundingSource> util = new ExcelUtil<FundingSource>(FundingSource.class);
        util.exportExcel(response, list, "资金来源数据");
    }

    /**
     * 获取资金来源详细信息
     */
    @RequiresPermissions("funding:source:query")
    @GetMapping(value = "/{sourceId}")
    public AjaxResult getInfo(@PathVariable("sourceId") Long sourceId)
    {
        return success(fundingSourceService.selectFundingSourceBySourceId(sourceId));
    }

    /**
     * 新增资金来源
     */
    @RequiresPermissions("funding:source:add")
    @Log(title = "资金来源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FundingSource fundingSource)
    {
        return toAjax(fundingSourceService.insertFundingSource(fundingSource));
    }

    /**
     * 修改资金来源
     */
    @RequiresPermissions("funding:source:edit")
    @Log(title = "资金来源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FundingSource fundingSource)
    {
        return toAjax(fundingSourceService.updateFundingSource(fundingSource));
    }

    /**
     * 删除资金来源
     */
    @RequiresPermissions("funding:source:remove")
    @Log(title = "资金来源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sourceIds}")
    public AjaxResult remove(@PathVariable Long[] sourceIds)
    {
        return toAjax(fundingSourceService.deleteFundingSourceBySourceIds(sourceIds));
    }


    /*获取所有资金来源信息*/
    @GetMapping("/getAllSource")
    public AjaxResult getAllSource()
    {
        List<FundingSource> list = fundingSourceService.selectFundingSourceList(null);
        return success(list);
    }





}
